﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Diagnostics;
namespace FloorDesigner
{
    static public class LayoutBuilder
    {
        public static LayoutManager Create(FrameworkElement tableElement, IEnumerable<Panel> allowedDropContainers, DesignMode mode, bool startDraggingOnMouseClick)
        {
            bool _allowCopy = false;
            bool _copy = false;

            switch (mode)
            {
                case DesignMode.Moving:
                    break;
                case DesignMode.DesignNew:
                    _allowCopy = true;
                    _copy = true;
                    break;
            }

            var _layoutManager = new LayoutManager(tableElement, allowedDropContainers, _allowCopy,_copy);

            if (startDraggingOnMouseClick)
            {
                tableElement.MouseLeftButtonDown += new MouseButtonEventHandler(_layoutManager.StartDragging);
                if (mode == DesignMode.DesignNew)
                    _layoutManager.CopiedElement += new EventHandler<CopiedEventArgs<FrameworkElement>>(layoutManager_CopiedElement);
            }

            return _layoutManager;
        }

        static void layoutManager_CopiedElement(object sender, CopiedEventArgs<FrameworkElement> e)
        {
            e.TableElement.MouseLeftButtonDown += 
                new MouseButtonEventHandler(((LayoutManager)sender).StartDragging);
        }

        public static LayoutManager Create(Control tableElement, IEnumerable<Panel> allowedDropContainers, DesignMode mode, bool startDraggingOnMouseClick)
        {
            return LayoutBuilder.Create((FrameworkElement)tableElement, allowedDropContainers, mode, startDraggingOnMouseClick);
        }
    }
}
